<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据集市列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>指标名称：</label>
                                <input type="text" name="naIndex"/>
                            </li>
                            <li>
                                <label>所属系统：</label>
                                <select name="sdSys" th:with="type=${@baseSd.getItem('hos_sys')}">
                                    <option value=""></option>
                                    <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.cd}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "etl/dm";
        function add() {
            $.modal.open("新建DM配置",prefix+"/add?type=1",900,600);
        };
        function createTable(idDrawDm) {
            $.ajax({
                url: prefix+'/createTable/'+ idDrawDm,
                type: 'GET',
                dataType: 'json',
                success: function (result) {
                    if(result.code=="0") {
                        $.modal.alertSuccess(result.msg);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $("#bootstrap-table").bootstrapTable('refresh');
                }
            });
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "数据集市",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'idDrawDm',
                    title: '',
                    visible: false
                },
                {
                    field: 'idIndex',
                    title: '指标'
                },
                {
                    field: 'naIndex',
                    title: '指标名'
                },
                {
                    field: 'cdTb',
                    title: '表名'
                },
                {
                    field: 'fgTb',
                    title: '可建表标志',
                    formatter: function(value, item, index) {
                        if(item.fgTb==1) {
                            return "是";
                        } else {
                            return "否"
                        }
                    }
                },
                {
                    field: 'euStatus',
                    title: '建表状态',
                    formatter: function(value, item, index) {
                        if(item.euStatus==0) {
                            return "未建表";
                        } else if(item.euStatus==1) {
                            return "已建表";
                        } else {
                            return "待重建";
                        }
                    }
                },
                {
                    field: 'sdSys',
                    title: '所属系统'
                },
                {
                    field: 'des',
                    title: '备注'
                },
                {
                    field: 'fgAct',
                    title: '启用标志',
                    formatter: function(value, item, index) {
                        if(item.fgAct==1) {
                            return "启用";
                        } else {
                            return "停用";
                        }
                    }
                },
                {
                    field: 'naEmpCre',
                    title: '创建人'
                },
                {
                    field: 'dtSysCre',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.idDrawDm + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.fgTb==1) {
                            actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="createTable(\'' + row.idDrawDm + '\')"><i class="fa fa-list-ul"></i>建表</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.idDrawDm + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>